package queue;

import array.CustomArray;

public class ArrayDeque<E> implements Deque<E> {
    private CustomArray<E> array;
    private int size;

    public ArrayDeque(int capacity) {
        array = new CustomArray<>(capacity);
        size = 0;
    }

    public ArrayDeque() {
        this(10);
    }

    @Override
    public void addFront(E e) {
        array.addFirst(e);
    }

    @Override
    public void addLast(E e) {
        array.addLast(e);
    }

    @Override
    public E removeFront() {
        return array.removeFirst();
    }

    @Override
    public E removeLast() {
        return array.removeLast();
    }

    @Override
    public int getSize() {
        return array.getSize();
    }

    @Override
    public boolean isEmpty() {
        return array.isEmpty();
    }

    @Override
    public E getFront() {
        return array.get(0);
    }

    @Override
    public E getLast() {
        return array.get(array.getSize() - 1);
    }

    @Override
    public String toString() {
        StringBuilder res = new StringBuilder();
        res.append(String.format("Queue: size = %d ,capacity= %d\n", getSize(), array.getCapacity()));
        res.append("front [");
        for (int i = 0; i < getSize(); i++) {
            res.append(array.get(i));
            if (getSize() != i + 1) {
                res.append(",");
            }
        }
        res.append("] tail");
        return res.toString();
    }
}
